import java.util.Arrays;

/**
 * 数组基础
 */
public class Demo01 {

  public static void main(String[] args) {

    //数字的变量定义
    int age = 20;//age只能存放一个值
    int[] ages = {12,32,12,15};
    int ages1[] = {22,33,44,55,11};//不推荐
    String[] names = {"张三","李四"};

    //数组的元素的访问
    //数字的下标 0~长度-1
    //获取数组的元素
    age = ages[0];//12
    System.out.println(age);
    age = ages[3];
    System.out.println(age);
    //设置数组的元素
    ages[2] = 13;
    System.out.println(ages1);//[I@1b6d3586
    for(int i=0;i<ages.length;i++){
      System.out.println(i+"="+ages[i]);
    }
    System.out.println(Arrays.toString(ages));

    //数组一旦声明完毕就固定了长度
    ages = new int[]{1,2,3,4,5,6};//长度6 //重新声明了一个新的数组
    System.out.println(ages);

    //java.lang.OutOfMemoryError 内存溢出
    int[] a = new int[Integer.MAX_VALUE];
    System.out.println(a);

  }

}
